/* ************************************************************************

   Copyright: Kim Pommert

   License: GPLv3

   Authors: Kim Pommert

************************************************************************ */

/* ************************************************************************

#asset(qooxdoosample/*)

************************************************************************ */

/**
 * This is the main application class of your custom application "QooxdooSample"
 */
qx.Class.define("qooxdoosample.Application",
{
  extend : qx.application.Standalone,


  /*
  *****************************************************************************
     MEMBERS
  *****************************************************************************
  */

  members :
  {
	toolBar: null,
	providerMenu: null,
	addressPanel: null,
	

    /**
     * This method contains the initial application code and gets called 
     * during startup of the application
     */
    main : function()
    {
      // Call super class
      this.base(arguments);

      // Enable logging in debug variant
      if (qx.core.Variant.isSet("qx.debug", "on"))
      {
        // support native logging capabilities, e.g. Firebug for Firefox
        qx.log.appender.Native;
        // support additional cross-browser console. Press F7 to toggle visibility
        qx.log.appender.Console;
      }

      /*
      -------------------------------------------------------------------------
        Below is your actual application code...
      -------------------------------------------------------------------------
      */
	

	  	// init UI components
	  	var layout = new qx.ui.layout.Grid();
		layout.setRowFlex(0, 1); // make row 0 flexible
		layout.setColumnFlex(2, 1);
		layout.setColumnWidth(0, 250);
		layout.setColumnWidth(1, screen.availWidth - 250 - 2);
		layout.setRowHeight(2, screen.availHeight - 380);

		var container = new qx.ui.container.Composite(layout);
			  
	  
		this.toolBar = new qooxdoosample.cocktail.ui.MapControlToolbar();
	  	
	  	var mapContainer = new qx.ui.embed.Html("<div id=\"map\" style=\"width: 100%; height: 100%\">map</div>");
	  	var routeContainer = new qx.ui.embed.Html("<div id=\"route\" style=\"width: 100%; height: 100%; overflow: auto;\"></div>");
	  	
	  	var routeScroller = new qx.ui.core.ScrollPane();
	  	routeScroller.add(routeContainer);
	  
	  	mapContainer.addListenerOnce("appear", function(e)
		{
   			this.providerMenu.init();
	  		this.toolBar.init(this.providerMenu.getMap());
	  		this.addressPanel.updateServices(this.providerMenu.getMap(), this.providerMenu.getGeocoder(), this.providerMenu.getRoute());
		}, this);
      	
      	// Route container
      	routeContainer.allowGrowX = true;
      	routeContainer.setPaddingTop(15);
        
        this.addressPanel = new qooxdoosample.cocktail.ui.AddressPanel();
        
        this.providerMenu = new qooxdoosample.cocktail.ui.ProviderMenuBar(this.addressPanel, this.toolBar);
        
           
      	
      	
        
        // add widgets to the panel
        container.add(this.providerMenu, {row:0, column: 0});
        container.add(this.addressPanel, {row: 1, column: 0});
      	container.add(this.toolBar, {row: 0, column: 1});
      	
      	container.add(mapContainer, {row: 1, column: 1, rowSpan: 2});
      	container.add(routeScroller, {row: 2, column: 0});
	  
	  	// add panel to website
		this.getRoot().add(container, {left: 1, top: 0});
    }
    
  }
});
